package com.hxkcloud.patient.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hxkcloud.patient.R;
import com.hxkcloud.patient.beans.SearchRecordBean;

import java.util.List;

/**
 * Created by Administrator on 2017/4/26.
 */

public class SearchRecordAdapter extends BaseAdapter {
    private Context context;
    private List<SearchRecordBean> data;

    public SearchRecordAdapter(Context context, List<SearchRecordBean> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView==null){
            convertView = View.inflate(context,R.layout.searchrecordadapter_item,null);
            holder = new ViewHolder();
            holder.tv_order = (TextView) convertView.findViewById(R.id.orders);
            holder.tv_consult = (TextView) convertView.findViewById(R.id.searchrecord_content);
            holder.tv_time = (TextView) convertView.findViewById(R.id.search_time);
            holder.tv_title = (TextView) convertView.findViewById(R.id.search_name);
            holder.ll_details = (LinearLayout) convertView.findViewById(R.id.searchrecord);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tv_order.setText(data.get(position).getOrderVer());
        holder.tv_time.setText(data.get(position).getTime());
        holder.tv_title.setText(data.get(position).getOtype());
        String consutl = data.get(position).getTags();
        if (consutl.length()>20){
            consutl = consutl.substring(0,20)+"......";
        }
        holder.tv_consult.setText(consutl);

        return convertView;
    }
    static  class ViewHolder{
        TextView tv_order;
        TextView tv_time;
        TextView tv_title;
        TextView tv_consult;
        LinearLayout ll_details;
    }
}
